<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="">
		<p> 用户名:<input type="text" name="user" value="" /><span id="rep"></span> </p>
		<p> <input type="submit" value="提交" /> </p>

	</form>
</body>
<script type="text/javascript">
	var inp = document.getElementsByTagName('input')[0];
	inp.onblur = function(){
		var xhr = new XMLHttpRequest();
		var data = 'name=' + this.value;
		var sp = document.getElementById('rep');
		xhr.onreadystatechange = function(){
			if(this.readyState = 4){
				if(this.responseText == 1){
					sp.innerHTML = 'YES';
				}else{
					sp.innerHTML = 'NO';
				}
			}
		
		}
		xhr.open('post','3.php',true);
		xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xhr.send(data);
	}
</script>
</html>